<?php
$r_url = "admin.php?file=userkj";
#[判断权限]
if($_SESSION["admin"]["typer"] != "system" && !$QG_AP["users"])
{
	Error("对不起，您没有权限操作当前功能","admin.php?file=index");
}
if($sysact == "add" || $sysact == "modify")
{
	if($sysAct == "modify")
	{
		$id = intval($id);
		if(!$id)
		{
			Error("操作非法！","admin.php?file=userkj&act=list");
		}
		$rs = $DB->qgGetOne("SELECT * FROM study WHERE c_id='".$id."'");
		$rsa = $DB->qgGetOne("SELECT c_name FROM city WHERE c_id='".$rs['c_id']."'");
		$rsb = $DB->qgGetOne("SELECT p_nickname FROM player_info WHERE u_id='".$rs[u_id]."'");

	
	}
}
elseif($sysact == "viewok")
{
	$id = intval($id);
	$msg = $STR->safe($_POST);
	if(!$msg["c_name"])
	{
		Error("用户名不能为空",$r_url."&act=".($id ? "modify" : "add")."&id=".$id);
	}
	if($id)
	{
		$rs = $DB->qgGetOne("SELECT * FROM ".$prefix."study WHERE c_id='".$id."'");
		$sql = "SELECT c_name FROM ".$prefix."study WHERE c_id!='".$id."' AND c_name='".$msg["c_name"]."'";
		$rschk = $DB->qgGetOne($sql);
		if($rschk)
		{
			Error("城池名称 ".$msg["c_name"]." 已经存在",$r_url."&act=modify&id=".$id);
		}
		$sql = "UPDATE study SET s_smelt='".$msg["s_smelt"]."',s_map='".$msg["s_map"]."',s_army='".$msg["s_army"]."',s_command='".$msg["s_command"]."',s_arm='".$msg["s_arm"]."',s_loricae='".$msg["s_loricae"]."',s_gee='".$msg["s_gee"]."',s_recovery='".$msg["s_recovery"]."',s_engine='".$msg["s_engine"]."',s_trajectory='".$msg["s_trajectory"]."',s_mining='".$msg["s_mining"]."',s_cutting='".$msg["s_cutting"]."',s_golds='".$msg["s_golds"]."',s_steel='".$msg["s_steel"]."',s_wheel='".$msg["s_wheel"]."',s_tactics='".$msg["s_tactics"]."',s_position='".$msg["s_position"]."',s_landform='".$msg["s_landform"]."',s_flooding='".$msg["s_flooding"]."' WHERE c_id='".$id."'";
		$DB->qgQuery($sql);		
		$r_url = $_SESSION["return_url"] ? $_SESSION["return_url"] : $r_url."&act=list";
		Error("城池信息更新成功",$r_url);
	}
	else
	{/*
		$sql = "SELECT username FROM ".$prefix."study WHERE username='".$msg["username"]."'";
		$rschk = $DB->qgGetOne($sql);
		if($rschk)
		{
			Error("城池名称 ".$msg["username"]." 已经存在",$r_url."&act=add");
		}
		$sql = "INSERT INTO ".$prefix."study(c_id,u_id,c_name,c_population,c_officers,c_soldiers,c_area,c_area_x,c_area_y,total_hills,free_hills,total_woodlands,free_woodlands,total_flats,free_flats,total_barracks,free_barracks,total_house,free_house,study_wall,c_img,c_size,c_total_size,c_land_type,c_type,create_date,ea_if) VALUES('','".$msg["u_id"]."','".$msg["c_name"]."','0','0','0','".$msg["c_area"]."','".$msg["c_area_x"]."','0','0','0','0','0','0','0','0','0','300','180','0','1','".$msg["c_size"]."','".$msg["c_total_size"]."','".$msg["c_land_type"]."','0','".time()."','1')";
		$DB->qgQuery($sql);*/
		Error("功能未开放！！！");
	}
}
elseif($sysact == "delete")
{
	$r_url = $_SESSION["return_url"] ? $_SESSION["return_url"] : $r_url."&act=list";
	$id = intval($id);
	if(!$id)
	{
		Error("操作非法",$r_url);
	}
	$sql = "DELETE FROM ".$prefix."study WHERE c_id='".$id."'";
	$DB->qgQuery($sql);
	Error("会员信息删除成功",$r_url);
}
elseif($act == "list")
{
	$page_url = "admin.php?file=userkj&act=list";
	$psize = 20;
	$pageid = intval($pageid);
	$offset = $pageid>0 ? ($pageid-1)*$psize : 0;
	$condition = "WHERE 1";
	$keywords = SafeHtml($keywords);
	$stype = SafeHtml($stype);
	if($keywords)
	{
		if($stype == "c_id")
		{
			$condition .= " AND c_id LIKE '%".$keywords."%'";
		}
		elseif($stype == "c_name")
		{
			$condition .= " AND c_name LIKE '%".$keywords."%'";
		}
		elseif($stype == "u_id")
		{
			$condition .= " AND email LIKE '%".$keywords."%'";
		}
		$page_url .= "&stype=".rawurlencode($stype)."&keywords=".rawurlencode($keywords);
	}
	$count = $DB->qg_count("SELECT count(c_id) FROM ".$prefix."study ".$condition);
	$pagelist = page($page_url,$count,$psize,$pageid);#[获取页数信息]
	$rslist = $DB->qgGetAll("SELECT * FROM ".$prefix."study ".$condition." ORDER BY c_id DESC LIMIT ".$offset.",".$psize);
}
Foot("userkj.qg");
?>